| Conditions | 1 | 
| Paths | 1 | 
| Total Lines | 61 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Changes | 1 | ||
| Bugs | 0 | Features | 0 | 
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | /** | ||
| 18 | function dark(state, format, visibility, upgrade, data, util) { | ||
| 19 | let ct = this; | ||
| 20 | ct.state = state; | ||
| 21 | ct.data = data; | ||
| 22 | ct.util = util; | ||
| 23 | ct.format = format; | ||
| 24 | |||
| 25 |   ct.darkProduction = function() { | ||
| 26 | let production = 0; | ||
| 27 |     for (let element in data.elements) { | ||
| 28 | let exotic = data.elements[element].exotic; | ||
| 29 |       if (!state.player.resources[exotic].unlocked) { | ||
| 30 | continue; | ||
| 31 | } | ||
| 32 | production += Math.floor(Math.max(0, Math.log(state.player.resources[exotic].number))); | ||
| 33 | } | ||
| 34 | |||
| 35 | return production; | ||
| 36 | }; | ||
| 37 | |||
| 38 |   ct.darkPrestige = function() { | ||
| 39 | let resources = state.player.resources; | ||
| 40 | let production = ct.darkProduction(); | ||
| 41 | |||
| 42 | resources.dark_matter.number += production; | ||
| 43 | resources.dark_matter.unlocked = true; | ||
| 44 | |||
| 45 |     for(let key in data.elements){ | ||
| 46 | // FIXME this is only necessary until all elements are implemented | ||
| 47 |       if(!state.player.elements[key]){ | ||
| 48 | continue; | ||
| 49 | } | ||
| 50 | let element = data.elements[key]; | ||
| 51 | state.player.resources[element.exotic].number = 0; | ||
| 52 | let exoticUpgrades = state.player.elements[key].exotic_upgrades; | ||
| 53 |       for (let up in exoticUpgrades) { | ||
| 54 | exoticUpgrades[up] = false; | ||
| 55 | } | ||
| 56 | upgrade.resetElement(state.player, key); | ||
| 57 | } | ||
| 58 | }; | ||
| 59 | |||
| 60 |   ct.buyDarkUpgrade = function(name) { | ||
| 61 | let upgrades = state.player.dark_upgrades; | ||
| 62 | let price = data.dark_upgrades[name].price; | ||
| 63 | let currency = 'dark_matter'; | ||
| 64 | upgrade.buyUpgrade(state.player, | ||
| 65 | upgrades, | ||
| 66 | name, | ||
| 67 | price, | ||
| 68 | currency); | ||
| 69 | }; | ||
| 70 | |||
| 71 |   ct.visibleDarkUpgrades = function(currentElement) { | ||
| 72 | return visibility.visible(data.dark_upgrades, isDarkUpgradeVisible, currentElement); | ||
| 73 | }; | ||
| 74 | |||
| 75 |   function isDarkUpgradeVisible(name, currentElement) { | ||
| 76 | return visibility.isUpgradeVisible(name, currentElement, data.dark_upgrades[name]); | ||
| 77 | } | ||
| 78 | } | ||
| 79 |